home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dmake / save / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-26  |  5.2 KB  |  280 lines

  1.  
  2. /*
  3.  *  MAIN.C
  4.  */
  5.  
  6. #include "defs.h"
  7. #ifdef AMIGA
  8. #include <intuition/intuition.h>
  9. #include <graphics/gfx.h>
  10. #include <clib/intuition_protos.h>
  11. #include <workbench/icon.h>
  12. #include <workbench/startup.h>
  13. #include <clib/wb_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <lib/misc.h>
  16. #endif
  17.  
  18. void help(int);
  19. void InitStuff(void);
  20. const char *SkipAss(const char *);
  21. #ifdef AMIGA
  22. struct IntuiText *ITextOf(char *);
  23. #endif
  24.  
  25. Prototype List    DoList;
  26. Prototype short DDebug;
  27. Prototype short NoRunOpt;
  28. Prototype short ExitCode;
  29. Prototype short    DoAll;
  30. Prototype short SomeWork;
  31.  
  32. List    DoList;
  33. short    DDebug;
  34. short    NoRunOpt;
  35. short    QuietOpt;
  36. short    DoAll;
  37. short   SomeWork;
  38. #ifdef AMIGA
  39. short    XSaveLockValid;
  40. BPTR    XSaveLock;
  41. #endif
  42. char    *XFileName = "DMakefile";
  43. short    FileSpecified = 0;
  44. short    ExitCode;
  45.  
  46. void
  47. myexit()
  48. {
  49. if (SomeWork)
  50.    printf("DMAKE Done.\n");
  51. else
  52.    printf("All Targets up to date.\n");
  53.  
  54. #ifdef AMIGA
  55.     if (XSaveLockValid) {
  56.     CurrentDir(XSaveLock);
  57.     XSaveLockValid = 0;
  58.     }
  59. #endif
  60. }
  61.  
  62. #ifdef AMIGA
  63.  
  64. wbmain(wbs)
  65. struct WBStartup *wbs;
  66. {
  67.     struct DiskObject *dob;
  68.     short i;
  69.     short j;
  70.     short abortIt = 0;
  71.  
  72.     /*
  73.      *    Search for options, set current directory to last valid
  74.      *    disk object
  75.      */
  76.  
  77.     InitStuff();
  78.  
  79.     for (i = 0; i < wbs->sm_NumArgs; ++i) {
  80.     BPTR saveLock = CurrentDir((BPTR)wbs->sm_ArgList[i].wa_Lock);
  81.  
  82.     if (i == wbs->sm_NumArgs - 1 && FileSpecified == 0)
  83.         XFileName = strdup(wbs->sm_ArgList[i].wa_Name);
  84.  
  85.     if (dob = GetDiskObject(wbs->sm_ArgList[i].wa_Name)) {
  86.         for (j = 0; dob->do_ToolTypes[j]; ++j) {
  87.         char *ptr = dob->do_ToolTypes[j];
  88.  
  89.         if (strnicmp(ptr, "FILE=", 5) == 0) {
  90.             XFileName = strdup(SkipAss(ptr));
  91.             FileSpecified = 1;
  92.         } else if (strnicmp(ptr, "DRYRUN=", 7) == 0) {
  93.             NoRunOpt = strtol(SkipAss(ptr), NULL, 0);
  94.         } else if (strnicmp(ptr, "TARGET=", 7) == 0) {
  95.             CreateDepRef(&DoList, SkipAss(ptr));
  96.         } else if (strnicmp(ptr, "QUIET=", 6) == 0) {
  97.             QuietOpt = strtol(SkipAss(ptr), NULL, 0);
  98.         } else if (strnicmp(ptr, "DEBUG=", 6) == 0) {
  99.             DDebug = strtol(SkipAss(ptr), NULL, 0);
  100.         } else if (strnicmp(ptr, "CONSOLE=", 8) == 0) {
  101.             OpenConsole(SkipAss(ptr)); /*  lib/misc.h  */
  102.         } else {
  103.             char buf[64];
  104.  
  105.             sprintf(buf, "Bad ToolType: %s", ptr);
  106.             switch(AutoRequest(NULL, ITextOf(ptr), ITextOf("Ignore"), ITextOf("Abort"), 0, 0, 300, 40)) {
  107.             case 1:
  108.             break;
  109.             case 0:
  110.             abortIt = 1;
  111.             break;
  112.             }
  113.         }
  114.         if (abortIt)
  115.             break;
  116.         }
  117.         FreeDiskObject(dob);
  118.     }
  119.     CurrentDir(saveLock);
  120.     if (abortIt)
  121.         break;
  122.     }
  123. #ifdef AMIGA
  124.     XSaveLock = CurrentDir((BPTR)wbs->sm_ArgList[wbs->sm_NumArgs-1].wa_Lock);
  125.     XSaveLockValid = 1;
  126. #endif
  127.  
  128.     if (abortIt == 0)
  129.     main(1, NULL);
  130. }
  131.  
  132. #endif
  133.  
  134. main(ac, av)
  135. char *av[];
  136. {
  137.     short i;
  138.     int r = 0;
  139.  
  140.     InitStuff();
  141.  
  142.     /*printf("ARGS= %d\n", ac);*/
  143.     for (i = 1; i < ac; ++i) {
  144.     char *ptr = av[i];
  145.  
  146.     /*printf("ARG[%d]= %d:%s\n", i, strlen(av[i]), av[i]);*/
  147.  
  148.     if (*ptr != '-') {
  149.         CreateDepRef(&DoList, ptr);
  150.         continue;
  151.     }
  152.     ptr += 2;
  153.     switch(ptr[-1]) {
  154.     case 'F':   /*  fast opt    */
  155.         break;
  156.     case 'f':
  157.         XFileName = (*ptr) ? ptr : av[++i];
  158.         break;
  159.     case 'n':
  160.         NoRunOpt = 1;
  161.         break;
  162.     case 'D':
  163.         (*ptr) ? ptr : av[++i];
  164.         var = MakeVar(name, '$');
  165.         AppendVar(var, value, len);
  166.         break;
  167.     case 'd':
  168.         DDebug = (*ptr) ? atoi(ptr) : 1;
  169.         break;
  170.     case 'a':
  171.         DoAll = 1;
  172.     case 'q':
  173.         QuietOpt = 1;
  174.         break;
  175.     case 'h':
  176.     default:
  177.         help(1);
  178.     }
  179.     }
  180.     if (QuietOpt == 0)
  181.     puts("DMake V2.1 " __DATE__);
  182.  
  183.     if (i > ac)
  184.     error(FATAL, "Expected argument to command line option");
  185.  
  186.     /*
  187.      *    resolve dependancies requested by the user.  If none requested
  188.      *    the resolve the first one
  189.      */
  190.  
  191.     {
  192.     DepRef *node;
  193.  
  194.     ParseFile(XFileName);
  195.  
  196.     if (GetHead(&DoList) == NULL) {
  197.         if (node = GetHead(&DepList))
  198.         CreateDepRef(&DoList, ((DepNode *)node)->dn_Node.ln_Name);
  199.     }
  200.  
  201.     while (node = RemHead(&DoList)) {
  202.         time_t t;
  203.             if ((node->rn_Dep->dn_Node.ln_Type != NT_RESOLVED) &&
  204.                (GetHead(&node->rn_Dep->dn_DepCmdList) == NULL))
  205.             {
  206.                 error(FATAL, "Unable to find %s", node->rn_Node.ln_Name);
  207.                 break;
  208.             }
  209.  
  210.         if ((r = ExecuteDependency(node, &t)) < 0)
  211.         {
  212.         break;
  213.             }
  214.     }
  215.     }
  216.     if (r < 0 && ExitCode < 20)
  217.     ExitCode = 20;
  218.     return(ExitCode);
  219. }
  220.  
  221. void
  222. InitStuff()
  223. {
  224.     static int Initialized;
  225.  
  226.     atexit(myexit);
  227.     if (Initialized == 0) {
  228.     Initialized = 1;
  229.     NewList(&DoList);
  230.     InitCommand();
  231.     InitCmdList();
  232.     InitVar();
  233.     InitDep();
  234.     InitParser();
  235.     }
  236. }
  237.  
  238. void
  239. help(code)
  240. int code;
  241. {
  242.     puts("DMAKE V2.1 (c)Copyright 1991 Matthew Dillon, All Rights Reserved");
  243.     puts("DMAKE [-f file] [-n]");
  244.     exit(code);
  245. }
  246.  
  247. const char *
  248. SkipAss(ptr)
  249. const char *ptr;
  250. {
  251.     while (*ptr && *ptr != '=')
  252.     ++ptr;
  253.     if (*ptr == '=') {
  254.     for (++ptr; *ptr == ' ' || *ptr == '\t'; ++ptr)
  255.         ;
  256.     }
  257.     return(ptr);
  258. }
  259.  
  260. #ifdef AMIGA
  261. struct IntuiText *
  262. ITextOf(ptr)
  263. char *ptr;
  264. {
  265.     static struct IntuiText ITAry[8];
  266.     static short ITIdx;
  267.     struct IntuiText *it = ITAry + ITIdx;
  268.  
  269.     ITIdx = (ITIdx + 1) & 7;
  270.     it->FrontPen = 1;
  271.     it->BackPen  = 0;
  272.     it->DrawMode = JAM2;
  273.     it->LeftEdge = 2;
  274.     it->TopEdge = 6;
  275.     it->IText = (unsigned char *)ptr;
  276.     return(it);
  277. }
  278. #endif
  279.  
  280.